package com.xisoft.devise.controller;

import cn.hutool.system.SystemUtil;
import com.xisoft.common.aspect.AppMonitorRuning;
import com.xisoft.common.enums.IdGenerator;
import com.xisoft.common.pubEnv.DateUtilbc;
import com.xisoft.common.pubEnv.StringUtil;
import com.xisoft.common.result.Result;
import com.xisoft.devise.entity.UserVO;
import com.xisoft.devise.service.IUserInfoService;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author xzh
 * @Date 2022/6/6 17:46
 * @Description
 * @Version 1.0
 **/
@RestController
@Api (value = "模型设计API接口")
@RequestMapping ("/user/")
public class UserInfoController
{

    @Qualifier ("UserInfoServiceImpl")
    @Autowired (required = false)
    private IUserInfoService userService;

    @PostMapping ("save")
    public Result save(UserVO userVO)
    {
        userVO = new UserVO();
        userVO.setUser_id(IdGenerator.INSTANCE.nextId());
        userVO.setUser_ip(SystemUtil.getHostInfo().getAddress());
        userVO.setUser_code(StringUtil.valueOfZero(System.currentTimeMillis()));
        userVO.setUser_qq("550583975");
        userVO.setUser_name("断剑留痕");
        userVO.setTs(DateUtilbc.currentDateTime());

        return Result.ok(userService.insert(userVO));
    }

    @PostMapping ("delete")
    public Result delete(@Param ("id") String id)
    {
        Map vo = (Map) userService.getSignKey(id);
        int i = userService.deleteById(id);
        return Result.ok(i);
    }

    @PostMapping ("update")
    public Result update(@RequestBody UserVO userVO)
    {
        userVO = new UserVO();
        userVO.setUser_id("202207281410583784096");
        userVO.setUser_ip(SystemUtil.getHostInfo().getAddress());
        userVO.setUser_code(StringUtil.valueOfZero(System.currentTimeMillis()));
        userVO.setUser_qq("550583975");
        userVO.setUser_name("断剑留痕01");
        userVO.setTs(DateUtilbc.currentDateTime());
        userService.updById(userVO);

        return Result.ok();
    }

    @GetMapping ("findById")
    @AppMonitorRuning (method = "UserInfoController.getObjById", funEffect = "findById！")
    public Result getObjById(@Param ("id") String id)
    { return Result.ok(userService.getSignKey(id)); }

}
